class QuestionsController < ApplicationController
  # GET /questions
  # GET /questions.xml
  # Get questions of current_user
  # url: 10.10.10.154:3000/questions.json
  def index
    puts "params: #{params.inspect}"
    user = User.find(params[:user_id])
    if user.role == USER_ROLE_STATUS[:teacher]
      
    end
    @questions = current_user ? current_user.questions : []

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @questions }
      format.json  { render :json => @questions }
    end
  end

  # POST /questions
  # POST /questions.xml
  # url: 10.10.10.154:3000/questions.json
  # params structure to create questions
  # question[:title] = ''
  # question[:grade_id] = ''
  # question[:subject_id] = ''  
  def create
    @question = Question.new(params[:question])
    @question.status = QUESTION_STATUS[:initial]
    #@question.student_id = current_user.id
    respond_to do |format|
      if @question.save
        flash[:notice] = 'Question was successfully created.'
        format.html { redirect_to(@question) }
        format.xml  { render :xml => @question, :status => :created, :location => @question }
        format.json { render :json => @question}
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @question.errors, :status => :unprocessable_entity }
        format.json { render :json => @question.errors, :status => :unprocessable_entity}
      end
    end
  end
end
